﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

/*
 * Image found at:
 * Bleeding Hand Wallpaper. Digital image. Snoron. Snoron, n.d. Web.
 * 29 Sept. 2014. <http://www.snoron.com/bleeding_hand-wallpapers.html>.
 * */

namespace CSE360_SudokuProject
{
    public partial class PauseMenu : Form
    {
        //variables
        MainGameScreen9x9 theGame9x9;
        MainGameScreen16x16 theGame16x16;
        LogInMenu loginParent;

        //constructor
        public PauseMenu(LogInMenu loginparent, MainGameScreen9x9 thegame9x9, 
            MainGameScreen16x16 thegame16x16)
        {
            InitializeComponent();
            loginParent = loginparent;
            theGame9x9 = thegame9x9;
            theGame16x16 = thegame16x16;
        }
        //
        // Reset Puzzle Button
        //
        private void ResetPuzzleButton_Click(object sender, EventArgs e)
        {
            //checks which board the user is on           
            if (ThePuzzleGenerator.is9x9)
            {
                //resets current to intial board data
                //shows the board form
                //redraws the board and enables the timer
                for (int i = 0; i < 9; i++)
                    for (int j = 0; j < 9; j++)                       
                        ThePuzzleGenerator.BoardCurrent9x9[i, j] = ThePuzzleGenerator.BoardInitial9x9[i, j];
                theGame9x9.LoadData();
                theGame9x9.Refresh();
                theGame9x9.Enabled = true;
                theGame9x9.Visible = true;
                theGame9x9.Timer.Enabled = true;
            }
            else if (ThePuzzleGenerator.is16x16)
            {
                //resets current to intial board data
                //shows the board form
                //redraws the board and enables the timer
                for (int i = 0; i < 16; i++)
                    for (int j = 0; j < 16; j++)
                        ThePuzzleGenerator.BoardCurrent16x16[i, j] = ThePuzzleGenerator.BoardInitial16x16[i, j];
                theGame16x16.LoadData();
                theGame16x16.Refresh();
                theGame16x16.Enabled = true;
                theGame16x16.Visible = true;
                theGame16x16.Timer.Enabled = true;
            }
            //closes the pause menu
            this.Close();
        }
        //
        // Quit Button
        //
        private void QuitButton_Click(object sender, EventArgs e)
        {
            //saves the data and closes the loginparent to end the game
            FileManager.SaveData();
            loginParent.Close();
        }
        //
        // Return to Game Button
        //
        private void ReturnToGameButton_Click(object sender, EventArgs e)
        {
            //checks which board the user is on and re-enables it and the timer
            if (ThePuzzleGenerator.is9x9)
            {
                theGame9x9.Enabled = true;
                theGame9x9.Visible = true;
                theGame9x9.Timer.Enabled = true;
            }
            else if(ThePuzzleGenerator.is16x16)
            {
                theGame16x16.Enabled = true;
                theGame16x16.Visible = true;
                theGame16x16.Timer.Enabled = true;
            }
            //close the pause menu
            this.Close();
        }
        //
        // Main Menu Button
        //
        private void MainMenuButton_Click(object sender, EventArgs e)
        {
            //checks which board the user is on
            if (ThePuzzleGenerator.is9x9)
            {
                //closes the board from and lets the form closing events of the board save the data
                //and create the main menu form
                theGame9x9.Close();
            }
            else if (ThePuzzleGenerator.is16x16)
            {
                //closes the board from and lets the form closing events of the board save the data
                //and create the main menu form
                theGame16x16.Close();
            }
            this.Close();
        }

        private void MercyButton_Click(object sender, EventArgs e)
        {
            //give up button
            //checks which board the user is playing
            if (ThePuzzleGenerator.is9x9)
            {
                //enables the board
                //hides all the input buttons
                theGame9x9.Visible = true;
                theGame9x9.Enabled = true;
                theGame9x9.Button1.Visible = false;
                theGame9x9.Button2.Visible = false;
                theGame9x9.Button3.Visible = false;
                theGame9x9.Button4.Visible = false;
                theGame9x9.Button5.Visible = false;
                theGame9x9.Button6.Visible = false;
                theGame9x9.Button7.Visible = false;
                theGame9x9.Button8.Visible = false;
                theGame9x9.Button9.Visible = false;
                theGame9x9.DeleteButton.Visible = false;
                theGame9x9.PauseButton.Visible = false;
                theGame9x9.HelpButton.Visible = false;
                theGame9x9.UndoButton.Visible = false;
                theGame9x9.currentSelectedNumber = 0;   
                //draws the correct answers to the board
                for (int i = 0; i < 9; i++)
                    for (int j = 0; j < 9; j++)
                        ThePuzzleGenerator.BoardCurrent9x9[i, j] = ThePuzzleGenerator.BoardAnswer9x9[i, j];
                theGame9x9.LoadData();
                //makes sure the game doesn't think the player won
                MainGameInputClass.wrongAnswerCount++;
                //forces the form to redraw
                theGame9x9.Refresh();
                //wipes the board data (and the saves by the closing event of the board)
                ThePuzzleGenerator.BoardAnswer9x9 = null;
                ThePuzzleGenerator.BoardInitial9x9 = null;
                ThePuzzleGenerator.BoardCurrent9x9 = null;
                //shows the button to return to the main menu
                theGame9x9.MerceyReturn.Visible = true;
                theGame9x9.MerceyReturn.Enabled = true;
                //changes the timer
                theGame9x9.Time.Text = "lol nope";
            }
            else if (ThePuzzleGenerator.is16x16)
            {
                //enables the board
                //hides all the input buttons
                theGame16x16.Visible = true;
                theGame16x16.Enabled = true;
                theGame16x16.button1.Visible = false;
                theGame16x16.button2.Visible = false;
                theGame16x16.button3.Visible = false;
                theGame16x16.button4.Visible = false;
                theGame16x16.button5.Visible = false;
                theGame16x16.button6.Visible = false;
                theGame16x16.button7.Visible = false;
                theGame16x16.button8.Visible = false;
                theGame16x16.button9.Visible = false;
                theGame16x16.button10.Visible = false;
                theGame16x16.button11.Visible = false;
                theGame16x16.button12.Visible = false;
                theGame16x16.button13.Visible = false;
                theGame16x16.button14.Visible = false;
                theGame16x16.button15.Visible = false;
                theGame16x16.button16.Visible = false;
                theGame16x16.deletebutton.Visible = false;
                theGame16x16.pausebutton.Visible = false;
                theGame16x16.helpbutton.Visible = false;
                theGame16x16.undobutton.Visible = false;
                theGame16x16.currentSelectedNumber = 0;
                //draws the correct answers to the board
                for (int i = 0; i < 16; i++)
                    for (int j = 0; j < 16; j++)
                        ThePuzzleGenerator.BoardCurrent16x16[i, j] = ThePuzzleGenerator.BoardAnswer16x16[i, j];
                theGame16x16.LoadData();
                //makes sure the game doesn't think the player won
                MainGameInputClass.wrongAnswerCount++;
                //forces the form to redraw
                theGame16x16.Refresh();
                //wipes the board data (and the saves by the closing event of the board)
                ThePuzzleGenerator.BoardAnswer16x16 = null;
                ThePuzzleGenerator.BoardInitial16x16 = null;
                ThePuzzleGenerator.BoardCurrent16x16 = null;
                //shows the button to return to the main menu
                theGame16x16.merceyreturn.Visible = true;
                theGame16x16.merceyreturn.Enabled = true;
                //changes the timer
                theGame16x16.Time.Text = "lol nope";
            }
            //closes the pause menu
            this.Close(); 
        }
    }
}
